<template>
  <div class="login-container">
    <el-form class="login-form" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left">
      <div class="title">账户登录</div>
      <el-form-item prop="username">
        <el-input  type="text" prefix-icon="el-icon-user" v-model="loginForm.username" size="large" auto-complete="on" placeholder="账 号" /></el-form-item>
      <el-form-item prop="password">
        <el-input  type="password" prefix-icon="el-icon-mima"  @keyup.enter.native="handleLogin" size="large" v-model="loginForm.password" auto-complete="on" placeholder="密 码" /></el-form-item>
      <el-form-item class="forget-plane">
        <el-checkbox style="float:left;color:#606266">记住密码</el-checkbox>
        <el-button style="float:right" type="text">忘记密码?</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="login-btn"  :loading="loading" @click.native.prevent="handleLogin">登 录</el-button></el-form-item>
    </el-form>
    <img src="~@/assets/user/logo.png" class="logo">
  </div>
</template>

<script>
import Login from '@/api/user'
export default {
  data () {
    return {
      loginForm: {
        username: 'admin',
        password: '123123'
      },
      loginRules: {
        username: [
          { required: true, trigger: 'blur', message: '请输入用户名' }
        ],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
      },
      loading: false,
      pwdType: 'password'
    }
  },
  methods: {
    Login (params) {
      Login(params).then(res => {
        //      console.log(res)
        this.loading = false
        this.$router.push({ path: '/index' })
      })
    },
    handleLogin () {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          //        var loginParams = {
          //          saleName:this.loginForm.username,
          //          passWord:this.loginForm.password
          //        }
          //        Login(loginParams)
          this.$store.dispatch('Login', this.loginForm).then(() => {
            this.loading = false
            this.$router.push({ path: '/index' })
            this.$router.go(0)
          }).catch(() => {
            this.loading = false
          })
        } else {
          return false
        }
      })
    }

  }
}
</script>

<style lang="scss">
.login-container{
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background-image: url('~@/assets/user/login_bg.jpg');
  background-size: 100% 100%;
  .login-form{
    background-color: #fff;
    border-radius: 4px;
    padding: 30px 60px;
    width: 450px;
  }
  .el-input__inner{
    padding-left: 36px;
  }
  .el-input__icon{
    font-size: 20px;
  }
  .login-btn{
    width: 100%;
    font-size: 20px;
    font-weight: 200;
  }
  .title{
    text-align: center;
    font-size: 24px;
    color:#3ca0ec;
    margin-bottom: 40px;
    font-weight: 200;
  }
  .logo{
    position: absolute;
    top: 40px;
    left: 100px;
    height: 25px;
  }
  .forget-plane{
    margin-bottom:8px;
    margin-top: -2px;
  }
}

</style>
